package com.anycl.design.behavioral.responsibility;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class Handler {
    public static final int DIFFICULTY_LEVEL_1_REQUEST = 1;
    public static final int DIFFICULTY_LEVEL_2_REQUEST = 2;
    public static final int DIFFICULTY_LEVEL_3_REQUEST = 3;
    // 能处理的级别
    private int level = 0;
    // 下一个责任人是谁
    private Handler nextHandler;

    public Handler(int level) {
        this.level = level;
    }

    public final void handleMessage(IRequest request) {
        if (request.getRequestLevel() <= this.level) {
            this.response(request);
        } else {
          if (this.nextHandler != null) {
              this.nextHandler.handleMessage(request);
          } else {
              log.info("难度级别为：" + request.getRequestLevel() + "的请求");
              log.info("没有工程师可以处理");
          }
        }
    }

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    protected abstract void response(IRequest request);
}
